import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { TechnicianScheduleApi } from '#/api/spa/technicians/schedule';

import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

import { DICT_SPA_TYPE } from '#/utils/dictSpa';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'technicianId',
      label: '技师ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入技师ID',
      },
    },
    {
      fieldName: 'scheduleDate',
      label: '排班日期',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'shiftType',
      label: '班次类型',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择班次类型',
      },
    },
    {
      fieldName: 'startTime',
      label: '开始时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'endTime',
      label: '结束时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'workHours',
      label: '工作时长(小时)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入工作时长(小时)',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'actualStartTime',
      label: '实际开始时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'actualEndTime',
      label: '实际结束时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'actualHours',
      label: '实际工作时长',
      component: 'Input',
      componentProps: {
        placeholder: '请输入实际工作时长',
      },
    },
    {
      fieldName: 'notes',
      label: '备注',
      component: 'Input',
      componentProps: {
        placeholder: '请输入备注',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'shiftCode',
      label: '班次编码',
      component: 'Input',
      componentProps: {
        placeholder: '请输入班次编码',
      },
    },
    {
      fieldName: 'isOvertime',
      label: '是否加班',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'boolean'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'overtimeHours',
      label: '加班时长',
      component: 'Input',
      componentProps: {
        placeholder: '请输入加班时长',
      },
    },
    {
      fieldName: 'breakTime',
      label: '休息时间(分钟)',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'statusReason',
      label: '状态变更原因',
      component: 'Input',
      componentProps: {
        placeholder: '请输入状态变更原因',
      },
    },
    {
      fieldName: 'statusChangedBy',
      label: '状态变更人ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入状态变更人ID',
      },
    },
    {
      fieldName: 'statusChangedTime',
      label: '状态变更时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'technicianId',
      label: '技师ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入技师ID',
      },
    },
    {
      fieldName: 'scheduleDate',
      label: '排班日期',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'shiftType',
      label: '班次类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择班次类型',
      },
    },
    {
      fieldName: 'startTime',
      label: '开始时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'endTime',
      label: '结束时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'workHours',
      label: '工作时长(小时)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入工作时长(小时)',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'actualStartTime',
      label: '实际开始时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'actualEndTime',
      label: '实际结束时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'actualHours',
      label: '实际工作时长',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入实际工作时长',
      },
    },
    {
      fieldName: 'notes',
      label: '备注',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入备注',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'shiftCode',
      label: '班次编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入班次编码',
      },
    },
    {
      fieldName: 'isOvertime',
      label: '是否加班',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'boolean'),
        placeholder: '请选择是否加班',
      },
    },
    {
      fieldName: 'overtimeHours',
      label: '加班时长',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入加班时长',
      },
    },
    {
      fieldName: 'breakTime',
      label: '休息时间(分钟)',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'statusReason',
      label: '状态变更原因',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入状态变更原因',
      },
    },
    {
      fieldName: 'statusChangedBy',
      label: '状态变更人ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入状态变更人ID',
      },
    },
    {
      fieldName: 'statusChangedTime',
      label: '状态变更时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<TechnicianScheduleApi.TechnicianSchedule>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    {
      field: 'technicianId',
      title: '技师ID',
      minWidth: 120,
    },
    {
      field: 'scheduleDate',
      title: '排班日期',
      minWidth: 120,
    },
    {
      field: 'shiftType',
      title: '班次类型',
      minWidth: 120,
    },
    {
      field: 'startTime',
      title: '开始时间',
      minWidth: 120,
    },
    {
      field: 'endTime',
      title: '结束时间',
      minWidth: 120,
    },
    {
      field: 'workHours',
      title: '工作时长(小时)',
      minWidth: 120,
    },
    {
      field: 'status',
      title: '状态',
      minWidth: 120,
    },
    {
      field: 'actualStartTime',
      title: '实际开始时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'actualEndTime',
      title: '实际结束时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'actualHours',
      title: '实际工作时长',
      minWidth: 120,
    },
    {
      field: 'notes',
      title: '备注',
      minWidth: 120,
    },
    {
      field: 'storeId',
      title: '门店ID',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'shiftCode',
      title: '班次编码',
      minWidth: 120,
    },
    {
      field: 'isOvertime',
      title: '是否加班',
      minWidth: 120,
    },
    {
      field: 'overtimeHours',
      title: '加班时长',
      minWidth: 120,
    },
    {
      field: 'breakTime',
      title: '休息时间(分钟)',
      minWidth: 120,
    },
    {
      field: 'statusReason',
      title: '状态变更原因',
      minWidth: 120,
    },
    {
      field: 'statusChangedBy',
      title: '状态变更人ID',
      minWidth: 120,
    },
    {
      field: 'statusChangedTime',
      title: '状态变更时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
